#include "../src/Server.hpp"
#include <cstring>

// int main()
// {
//     Socket sock;
//     sock.CreateClient("127.0.0.1", 9000);
    
//     for(int i = 0; i < 5; ++i)
//     {
//         const char* str = "hello world";
//         // int n = write(sock.Fd(), str, strlen(str));
//         int n = send(sock.Fd(), str, strlen(str), 0);
//         sleep(1);
//     }

//     return 0;
// }




// int main()
// {
//     Socket sock;
//     assert(sock.CreateClient("127.0.0.1", 9000));
    
//     DBG_LOG("client socket created %d", sock.Fd());

//     const char* str = "hello world";
//     ssize_t n = sock.Send(str, strlen(str));
//     if(n < 0) abort();

//     DBG_LOG("client send data");

//     char buf[1024] = { 0 };
//     n = sock.Recv(buf, 1023);
//     if(n < 0) abort();

//     DBG_LOG("server say: %s", buf);

//     return 0;
// }




int main()
{
    Socket sock;
    assert(sock.CreateClient("127.0.0.1", 9000));
    
    INF_LOG("client socket created %d", sock.Fd());

    for(int i = 0; i < 5; ++i)
    {
        char buf[1024] = { 0 };
        sprintf(buf, "%s %d", "hello world", i + 1);
        ssize_t n = sock.Send(buf, strlen(buf));
        if(n < 0)
        {
            ERR_LOG("server has closed connection");
            return 0;
        }

        INF_LOG("client send data: %s", buf);

#if 0
        bzero(buf, 1024);
        n = sock.Recv(buf, 1023);
        if(n < 0)
        {
            ERR_LOG("server has closed connection");
            return 0;
        }

        INF_LOG("server say: %s", buf);
#endif

        sleep(1);
    }

    INF_LOG("communication end");

    while(true)
    {
        sleep(1);
    }

    return 0;
}